package com.zjzywl.smoke.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zjzywl.smoke.entity.Device;
import com.zjzywl.smoke.entity.DeviceStatus;
import com.zjzywl.smoke.repository.DeviceRepository;
import com.zjzywl.smoke.repository.DeviceStatusRepository;
import com.zjzywl.smoke.service.DeviceService;
@Service
public class DeviceServiceImpl implements DeviceService {
	@Autowired
	private DeviceRepository deviceRepository;
	@Autowired
	private DeviceStatusRepository deviceStatusRepository;

	@Override
	public Device save(Device device) {
		Device save = deviceRepository.save(device);
		return save;
	}
	@Override
	public void deleteDevice(int deviceid) {
		deviceRepository.deleteDevice(deviceid);
	}
	
	@Override
	public void updateFirCount(String devCode, int fireCount) {
		deviceRepository.updateFirCount(devCode,fireCount);		
	}
	@Override
	public Device findByDeviceCode(String devCode) {
		Device device = deviceRepository.findByDeviceCode(devCode);	
		return device;
	}
	@Override
	public List<Device> findByUserAndDeviceTypeAndAddressLike(String userId, String deviceTypeId,String  status ,String string) {
		List<Device> devices = deviceRepository.findByUserAndDeviceTypeAndAddressLike(userId, deviceTypeId,
				 status,string);
		return devices;
	}
	@Override
	public Long getDeviceCountByUserAndDeviceTypeAndStatus(String userId, String devicetypeid, String status) {
		Long count =deviceRepository.findDeviceCountByUserAndDeviceTypeAndStatus(userId,devicetypeid,status);
		return count;
	}

	
}
